/*

The Effect of Personalized Feedback on Small Enterprises' Finances in Uganda
Antonia Grohmann, Lukas Menkhoff, Helke Seitz

Table 5

*/  
 
set varabbrev off
set more off
cap log close
set mem 500m
clear

/*------[Matrix Start]------*/
set obs 9
forval i= 1(1)10{							
gen Spalte`i' = .
mkmat Spalte`i'
}
mkmat Spalte1 Spalte2 - Spalte5, matrix(matrixd)   

drop Spalte*
/*------[Matrix End]------*/

use "filepath\Uganda_shortterm.dta", clear




xtset ID_2012_firm wave




/*Groups */

 
local sample=2
#del;
local 
tex_vars3 
rulethumb personalized   
;
#del cr  
  
     

	
foreach spec in 1 2 3 4 5 {



 
	             
    if `spec'==1 { 
   #del;
    local lhs 
	z_inv2_v0`sample'
	;
	local rhs  
    lz_inv2_v0`sample' personalized rulethumb ind2 ind3 ind4
	 ; 
	local estcommand = "reg"
	;
	local estoptions = "cluster(ID_2012_firm)"
	;
   #del cr
   } 
       
    if `spec'==2 { 
   #del;
    local lhs 
	invyes_v1
	;
	local rhs  
    linvyes_v1 personalized rulethumb ind2 ind3 ind4
	 ; 
	local estcommand = "reg"
	;
	local estoptions = "cluster(ID_2012_firm)"
	;
   #del cr
   }
   
       	

       
    if `spec'==3 { 
   #del;
    local lhs 
	invam_v1_correct_help2_w
	;
	local rhs  
    linvam_v1_correct_help2_w personalized rulethumb ind2 ind3 ind4
	 ; 
	local estcommand = "reg"
	;
	local estoptions = "cluster(ID_2012_firm)"
	;
   #del cr
   }
         

   
 
     
	
       if `spec'==4 { 
   #del;
    local lhs 
	invno_v1
	;
	local rhs  
    linvno_v1 personalized rulethumb ind2 ind3 ind4
	 ; 
	local estcommand = "reg"
	;
	local estoptions = "cluster(ID_2012_firm)"
	;
   #del cr
   }  
 
 
 
       if `spec'==5 { 
   #del;
    local lhs 
	inventory_v02_correct_w
	;
	local rhs  
    linventory_v02_correct_w personalized rulethumb ind2 ind3 ind4
	 ; 
	local estcommand = "reg"
	;
	local estoptions = "cluster(ID_2012_firm)"
	;
   #del cr
   }    
	
	  foreach num of numlist 1 {

      `estcommand'  `lhs' `rhs'  if  sample_v0`sample'==1 & sample_inv1_v0`sample'==1, `estoptions'
	   
	   local obs`spec'=e(N) 
	   test _b[personalized]-_b[rulethumb]=0
	   local ttest`spec'=r(p)
	   local r2`spec'=	e(r2)
	   sum `lhs' if control==1 & sample_v0`sample'==1 & sample_inv1_v0`sample'==1
	   local meany`spec'=r(mean)
	   local sdy`spec' =sqrt(r(Var))
	   

	  if ("`spec'"=="1" & "`num'"=="1") {
		 
		 
		   #del;
			est2vec est_v5
				, 
				vars(`tex_vars3') 
				replace name(out`spec'`num');
				
				est2extlbl, addto(est_v5) 
				intex("${TEMP_PATH}/texlabels_e_v01.tex") path(${ESTIMATION_PATH}) 
				replace dropall saving;
			 
						
		  #del cr
		 } /*if*/
		 else {
						est2vec est_v5, addto(est_v5) name(out`spec'`num')

		 } /*else*/
		 #del;
					est2tex8 est_v5, replace preserve 
					path(${ESTIMATION_PATH})
					mark(starb) levels(90 95 99) digits(3) 
					fancy leadzero thousep;
					#del cr
		 
	  
	  
	  
}
}



wyoung, cmd("regress invyes_v1 linvyes_v1 personalized rulethumb ind2 ind3 ind4" "regress invam_v1_correct_help2_w linvam_v1_correct_help2_w personalized rulethumb ind2 ind3 ind4" "regress invno_v1 linvno_v1 personalized rulethumb ind2 ind3 ind4"  "regress inventory_v02_correct_w linventory_v02_correct_w personalized rulethumb ind2 ind3 ind4"    )  cluster(ID_2012_firm) familyp(rulethumb) bootstraps(100) seed(20)

matrix A= r(table)
matrix list A


wyoung, cmd("regress invyes_v1 linvyes_v1 personalized rulethumb ind2 ind3 ind4" "regress invam_v1_correct_help2_w linvam_v1_correct_help2_w personalized rulethumb ind2 ind3 ind4" "regress invno_v1 linvno_v1 personalized rulethumb ind2 ind3 ind4" "regress inventory_v02_correct_w linventory_v02_correct_w personalized rulethumb ind2 ind3 ind4"   ) cluster(ID_2012_firm) familyp(personalized) bootstraps(100) seed(20)

matrix B= r(table)
matrix list B

foreach spec of numlist 1(1)5 {

matrix matrixd[1,1]=.
matrix matrixd[1,2]=round(A[1,4],.01)
matrix matrixd[1,3]=round(A[2,4],.01)
matrix matrixd[1,4]=round(A[3,4],.01)
matrix matrixd[1,5]=round(A[4,4],.01)

matrix matrixd[2,1]=.
matrix matrixd[2,2]=round(B[1,4],.01)
matrix matrixd[2,3]=round(B[2,4],.01)
matrix matrixd[2,4]=round(B[3,4],.01)
matrix matrixd[2,5]=round(B[4,4],.01)

matrix matrixd[3,`spec']=round(`ttest`spec'',.01)
matrix matrixd[4,`spec']=round(`r2`spec'',.01)
matrix matrixd[5,`spec']=round(`meany`spec'',.01)
matrix matrixd[6,`spec']=round(`sdy`spec'',.01)
matrix matrixd[7,`spec']=round(`obs`spec'',.01)
matrix matrixd[8,`spec']=1
matrix matrixd[9,`spec']=1

}

matrix rownames matrixd =  FWER_Finance_Training FWER_Finance_Training_+_Feedback A-B=0(p-value) R$2$ Mean(SD)of$y_t$in controlgroup Observations y${t-1}$covariate strata

matrix list matrixd
outtable using ${DESC_PATH}/est_v5a, mat(matrixd)  replace  f(%9.2f )




